class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :set_user_language
  
  
   def require_login
    if !session[:user]
      redirect_to session_login_path
    end
  end
  
  def remember_location
  session[:back_paths] ||= []
  unless session[:back_paths].last == request.fullpath
    session[:back_paths] << request.fullpath
  end

  # make sure that the array doesn't bloat too much
  session[:back_paths] = session[:back_paths][-10..-1]
end

def back
  session[:back_paths] ||= []
  session[:back_paths].pop || :back
end
  
  private
  def set_user_language
    if session[:language]
      language = session[:language]
      if language == 'vi'
        I18n.locale = 'vi'
      elsif language == 'en'
        I18n.locale = 'en'
      else
        I18n.locale = 'en'        
      end
    else
      I18n.locale = 'en'
    end
  end
end
